package com.example.projectcode.controller.Teacher;

import com.example.projectcode.model.Kdpoints;
import com.example.projectcode.model.Subject;
import com.example.projectcode.result.Result;
import com.example.projectcode.service.KdpointsService;
import com.example.projectcode.service.SubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@Api(tags = "科目重难点接口")
@RequestMapping(value = "/teacher/kdpointsManage")
public class KdpointsManageController {

    @Autowired
    private SubjectService subjectService;

    @Autowired
    private KdpointsService kdpointsService;

    @ApiOperation("显示科目")
    @GetMapping(value = "/displaySubject")
    public Result displaySubject(){
        List<Subject> list = new ArrayList<>();
        list = subjectService.selectAllSubject();
        return Result.ok(list);
    }

    @ApiOperation("根据科目id查询对应的重难点")
    @GetMapping(value = "selectKdpointsBySubId/{SubId}")
    public Result displaykdpointsBySubId(@PathVariable Integer SubId){
        List<Kdpoints> kdpointsList = new ArrayList<>();
        kdpointsList = kdpointsService.selectKdpointsBySubId(SubId);

        return Result.ok(kdpointsList);
    }

    @ApiOperation("添加某科目下的重难点")
    @GetMapping(value = "/insertkpoints/{SubName}/{K_Dcontent}")
    public Result insertkpoints(@PathVariable String SubName, @PathVariable String K_Dcontent){
        int result = kdpointsService.insertkdpoints(SubName,K_Dcontent);
        if (result>0){
            return Result.ok().message("添加成功");
        }else {
            return Result.fail().message("添加失败");
        }
    }

    @ApiOperation("根据重难点Id修改重难点")
    @GetMapping(value = "/updatekpoints/{K_Did}/{K_Dcontent}")
    public Result updatekpoints(@PathVariable Integer K_Did, @PathVariable String K_Dcontent){
        int result = kdpointsService.updatekdpoints(K_Did,K_Dcontent);
        if (result>0){
            return Result.ok().message("修改成功");
        }else {
            return Result.fail().message("修改失败");
        }
    }

    @ApiOperation("根据重难点Id删除重难点")
    @GetMapping(value = "/deletekpoints/{K_Did}")
    public Result deletekpoints(@PathVariable Integer K_Did){
        int result = kdpointsService.deletekdpoints(K_Did);
        if (result>0){
            return Result.ok().message("删除成功");
        }else {
            return Result.fail().message("删除失败");
        }
    }

}
